package cl.uchile.sketchpad.persistance.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;

import static javax.persistence.FetchType.*;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "subject")
@JsonIgnoreProperties({"teachers"})
public class Subject implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8742585504045980674L;
	
	private Integer id;
	private String name;
	
	private Set<User> teachers = new LinkedHashSet<User>();
	private List<SubjectVersion> subjectVersions = new ArrayList<SubjectVersion>(0);

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToMany(fetch = LAZY)
	@JoinTable(name = "subject_teacher",
			joinColumns = { @JoinColumn(name = "subject_id") },
			inverseJoinColumns = { @JoinColumn(name = "user_id") })
	public Set<User> getTeachers() {
		return teachers;
	}

	public void setTeachers(Set<User> teachers) {
		this.teachers = teachers;
	}

	@OneToMany(fetch = LAZY, mappedBy = "subject")
	@OrderBy("name")
	public List<SubjectVersion> getSubjectVersions() {
		return subjectVersions;
	}

	public void setSubjectVersions(List<SubjectVersion> subjectVersions) {
		this.subjectVersions = subjectVersions;
	}
	
	
	
}
